<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 71027
  Date: 2019/5/9
  Time: 18:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>所有宠物</title>
    <%@include file="common/common.jsp"%>
    <%--引入一个JSP--%>

    <%--<script src="<c:url value="/twitter-bootstrap/twitter-bootstrap-v2/js/bootstrap-modal.js"/>"></script>--%>
</head>
<body>
<h1>欢迎你,${userid}</h1>
<h1>查看所有宠物</h1>
<div>条件查找</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

                <h4 class="modal-title" id="myModalLabel">宠物详情</h4>
            </div>

            <div class="modal-body">

                <div id="ii">${mypetshowlist.get(0).petid}</div>
                <div>${mypetshowlist.get(0).petid}</div>
                <table>

                    <tr>
                        <td>序号</td>
                        <td>宠物id</td>
                        <td>宠物名称</td>
                        <td>宠物照片</td>
                        <td>宠物性别</td>
                        <td>宠物年龄</td>
                        <td>宠物健康</td>
                        <td>宠物类别</td>
                        <td>发布时间</td>
                        <td>宠物是否已售出</td>
                        <td style="color: red">宠物价格</td>
                    </tr>

                    <c:forEach items="${allpetlist}" var="allpetlist" varStatus="i">
                        <tr>
                            <td>${i.count}</td>
                            <td>${allpetlist.petid}</td>
                            <td>${allpetlist.petdetails.petname}</td>
                            <td>${allpetlist.petdetails.petphotopath}</td>
                            <td>${allpetlist.petdetails.gender}</td>
                            <td>${allpetlist.petdetails.age}</td>
                            <td>${allpetlist.petdetails.health}</td>
                            <td>${allpetlist.petdetails.species}</td>
                            <td>${allpetlist.petrelease.releasetime}</td>
                            <td>${allpetlist.pettrading.flag}</td>
                            <td style="color: red">${allpetlist.pettrading.money}</td>
                        </tr>
                    </c:forEach>
                </table>

            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<table>
    <tr>
        <td>序号</td>
        <td>宠物id</td>
        <td>商店id</td>
        <td>宠物名称</td>
        <td>宠物照片</td>
        <td>宠物性别</td>
        <td>宠物年龄</td>
        <td>宠物健康</td>
        <td>宠物类别</td>
        <td>发布时间</td>
        <td>宠物是否已售出</td>
        <td style="color: red">宠物价格</td>
    </tr>
    <c:forEach items="${allpetlist}" var="allpetlist" varStatus="i">
        <tr>
            <td>${i.count}</td>
            <td>${allpetlist.petid}</td>
            <td>${allpetlist.storeid}</td>
            <td>${allpetlist.petdetails.petname}</td>
            <td>${allpetlist.petdetails.petphotopath}</td>
            <td>${allpetlist.petdetails.gender}</td>
            <td>${allpetlist.petdetails.age}</td>
            <td>${allpetlist.petdetails.health}</td>
            <td>${allpetlist.petdetails.species}</td>
            <td>${allpetlist.petrelease.releasetime}</td>
            <td>${allpetlist.pettrading.flag}</td>
            <td style="color: red">${allpetlist.pettrading.money}</td>
            <td>
                <button data-toggle="modal" data-target="#myModal" onclick="datainput('${allpetlist.petid}')">详细</button>
            </td>

            <td><button onclick="buy('${allpetlist.petid}')">购买</button></td>
        </tr>
    </c:forEach>
<%----%>

</table>

<script>
    function datainput(number) {
        document.getElementById('ii').innerText=number;
    }
    function buy(petid) {
        alert(petid);
        $.ajax({
            url:"http://localhost:8080/Github_war_exploded/pet/buyaction",
            data:{
                buyerid:'${userid}',
                petid:petid
            },
            success:function (data) {
                window.location.reload();
            },error:function (msg) {
                alert('ajax error!');
            }
        });
    }
</script>
</body>
</html>
